﻿
@{
    ViewBag.Title = "Employee";
    Layout = "~/Views/Shared/Index.cshtml";
}
@model  List<YaYun.Models.Employee>
@{

}

<style>
    .btne {
        background-color: #0094ff; /* Green */
        border: none;
        color: white;
        padding: 6px 12px;
        text-align: center;
        text-decoration: none;
        display: inline-block;
        font-size: 12px;
        -webkit-transition-duration: 0.4s; /* Safari */
        transition-duration: 0.4s;
        border-radius: 5px; /* Green */
    }

       
    .wi {
        background-color: azure;
    }

    .re {
        background-color: pink;
    }

    .el-textarea__inner {
        width:300px;
     
        padding: 5px 15px;
        line-height: 1.5;
        box-sizing: border-box;
        width: 20%;
        font-size: inherit;
        color: #606266;
        background-color: #fff;
      
        border: 1px solid #dcdfe6;
        border-radius: 4px;
        transition: border-color .2s cubic-bezier(.645,.045,.355,1);
    }

 

    .el-button {
        display: inline-block;
        line-height: 1;
        white-space: nowrap;
        cursor: pointer;
        background-color: #409eff;
        border: 1px solid #dcdfe6;
        color: #606266;
        -webkit-appearance: none;
        text-align: center;
        box-sizing: border-box;
        outline: none;
        margin: 0;
        transition: .1s;
        color: #fff;
        font-weight: 500;
        -moz-user-select: none;
        -webkit-user-select: none;
        -ms-user-select: none;
        padding: 12px 20px;
        font-size: 14px;
        border-radius: 4px;
    }
 
        .el-buttona

    {
        display: inline-block;
        line-height: 1;
        white-space: nowrap;
        cursor: pointer;
        background: #fff;
        border: 1px solid #dcdfe6;
        color: #606266;
        -webkit-appearance: none;
        text-align: center;
        box-sizing: border-box;
        outline: none;
        margin: 0;
        transition: .1s;
        font-weight: 500;
        -moz-user-select: none;
        -webkit-user-select: none;
        -ms-user-select: none;
        padding: 12px 20px;
        font-size: 14px;
        border-radius: 4px
    }
    #employeeForm{
        float:right;
        width:80%;
    }
   
</style>

<div>
    <div style="">

        <h3>员工信息管理</h3>
        <a class="el-button--primary   el-buttona" href="/home/ADDEmployee">添加新员工</a>

        @*真的是服了*@
        <span style="display:none;float:left">
            @using (Html.BeginForm("Employee", "Home", FormMethod.Post, new { id = "" }))
            {
                <input type="text" class="el-textarea__inner" name="name" value="@ViewBag.SearchName">
                <input type="submit" class="layui-btn" value="查询员工" />
            }

        </span>

        @using (Html.BeginForm("Employee", "Home", FormMethod.Post, new { id = "employeeForm" }))
        {
            <input type="text" class="el-textarea__inner" name="name" placeholder="输入姓名查询" value="@ViewBag.SearchName">
            <button type="submit" class="layui-btn">查询</button>
        }


        <div class="add_emp" style="display:none">

            <h2>入职信息登记</h2>
            @using (Html.BeginForm())
            {
                <svg width="27" height="27" onclick="qiandao_close()" class="qiandao_close" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <path d="M8 8L40 40" stroke="#FF0000" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" />
                    <path d="M8 40L40 8" stroke="#FF0000" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" />
                </svg>

                <span>电话号码：</span> <input type="text" maxlength="11" name="phone" value="" /> <br /><br />
                <span>电子邮箱：</span> <input class="input-group" type="text" name="email" value="" /> <br /><br />
                <span>员工姓名：</span> <input type="text" name="EmployeeName" value="" /> <br /><br />
                <span>性别：</span> <input type="text" name="gender" value="" /> <br /><br />
                <span>部门：</span> <input type="text" name="department_id" value="" /><br /><br />

                <span>职务：</span> <input type="text" name="position_id" value="" /> <br /><br />
                <span>入职时间：</span> <input type="date" name="enter_date" value="" /> <br /><br />
                <input type="submit" value="提交" />
            }

        </div>
    </div>
    <table class="layui-table layui-form">
        <thead>
            <tr>
                <th class="emp_id_td">员工编号</th>
                <th class="emp_tr_t">手机号</th>
                <th class="emp_tr_t">邮箱</th>
                <th class="emp_tr_t">员工姓名</th>
                <th class="emp_tr_t">性别</th>
                <th class="emp_tr_t">所在部门</th>
                <th class="emp_tr_t">职务</th>

                <th class="emp_tr_t">入职时间</th>
                <th class="emp_tr_t">状态</th>
                <th class="emp_tr_t">操作</th>
            </tr>
        </thead>
        @{
            int numid = 1;
        }
        @foreach (var item in Model)
        {
            <tr class="tr_hover">
                <td class="emp_id_td">@numid</td>
                <td class="emp_tr_t">@item.phone</td>
                <td class="emp_tr_t">@item.email</td>
                <td class="emp_tr_t">@item.EmployeeName</td>
                <td class="emp_tr_t">@item.gender</td>
                <td class="emp_tr_t">@item.Department1.DepartmentName</td>
                <td class="emp_tr_t">@item.Position1.PositionName </td>

                @{
                    var date = item.enter_date;
                    var strdate = "";
                    if (date != null)
                    {
                        strdate = DateTime.Parse(date.ToString()).ToString("yyyy年MM月dd日");
                    }
                }
                <td class="emp_tr_t">@strdate</td>

                <td class="emp_tr_t @(item.state==0?"":"re")">

                    @(item.state==0?"在职":"离职")  
                </td>

                <td class="emp_tr_t">
                    <input type="button" style="font-size:12px" class=" layui-btn " onclick="change(@item.id,@item.state,'@item.EmployeeName')" value="设置" />
                    <input type="button" style="font-size:12px" class="btn btn-link" onclick="edit(@item.id)" value="详情" />
                </td>

            </tr>
            numid++;
        }
    </table>

</div>
<div class="demo-laypage-pn-show">
    @Html.ActionLink("上一页", "Employee", new { page = ViewBag.CurrentPage - 1 }, new { @class = "layui-btn" })
    @for (int i = 1; i <= ViewBag.TotalPages; i++)
    {
        if (i == ViewBag.CurrentPage)
        {
            @Html.Label($"{@i}", new { @class = "layui-btn layui-btn-sm layui-btn-warm" }) ;
        }
        else
        {
            @Html.ActionLink(i.ToString(), "Employee", new { page = i }, new { @class = "layui-btn layui-btn-primary layui-btn-sm" });
        }
    }
    @Html.ActionLink("下一页", "Employee", new { page = ViewBag.CurrentPage + 1 }, new { @class = "layui-btn" })
</div>

    <script>
        function change(id, state,name) {       
            if (confirm("是否确认要为 "+ name +' 办理离职')) {

         
            $.ajax({
                url: '/home/EmpDel',
                type: 'POST',
                data: { id, state },
                success: function (result) {
                    alert('修改成功');
                    location.reload();
                    // 获取当前的分页参数
                    var currentPage = getCurrentPage(); // 自定义函数，用于获取当前页码
                    var pageSize = getPageSize(); // 自定义函数，用于获取每页显示的数量

                    // 构建重定向的 URL
                    var redirectUrl = '/home?page=' + currentPage + '&pageSize=' + pageSize;

                    // 添加一个特殊的查询参数
                    redirectUrl += '&refresh=true';

                    // 重定向到当前页面的 URL
                    window.location.href = redirectUrl;
                
                },
                error: function (xhr, status, error) {
                    // 处理错误    alert('ok');
                    alert('修改失败');
                }
            });

            // 在页面加载时检查查询参数并执行刷新
            $(document).ready(function () {
                var urlParams = new URLSearchParams(window.location.search);
                var refresh = urlParams.get('refresh');

                if (refresh === 'true') {
                    // 执行页面刷新
                    location.reload();
                }
            });
            }
        }

        function edit(id) {
            window.location = ("/home/edit?id=" + id)
            }

    </script>
